Skip to content

Add react router links to Breadcrumbs #59

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 20, 2025

Conversation

VictoriaBeilsten-Edmands
Copy link
Collaborator

@VictoriaBeilsten-Edmands VictoriaBeilsten-Edmands commented May 2, 2025

Adds LinkComponent prop for page routing. Closes #56.
Reorganises components to mirror Storybook component structure.
Fixes type issue with image in Footer and Navbar.
I had to add yet another config file to get the tests running due to an issue with react-router-dom v7. See here and here.

Copy link
Member

@akademy akademy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This didn't work "out of the box" for me when I used it in my external app, because I didn't have <BrowserRouter> added.

I'm not sure how to handle this. Maybe we could add it to some-kind of <SciReactProvider/> (which could also embed the theme) so that just the one line can be added in external apps. Something like:

const SciReactUIProvider = function ({children}) {
  return (
    <ThemeProvider>
      <BrowserRouter>
        {children}
      </BrowserRouter>
    </ThemeProvider>
  );
};

The alternative is to just add it to the docs but I like to hide, behind the scenes, as much as we can What do you think?

@VictoriaBeilsten-Edmands
Copy link
Collaborator Author

We could create the SciReactUIProvider which would leave the Breadcrumbs component unchanged and would leave the option for people to use e.g. RouterProvider in place of BrowserProvider together withe the ThemeProvider. I should still update the docs with something.

@akademy
Copy link
Member

akademy commented May 6, 2025

I thought we still had to change Breadcrumbs to use ReactRouter's Link though. Or does it just pick up MUI's version?

@VictoriaBeilsten-Edmands
Copy link
Collaborator Author

My comment was unclear! I mean leave the Breadcrumbs component unchanged from how it is in this PR.

@VictoriaBeilsten-Edmands VictoriaBeilsten-Edmands force-pushed the vbe/breadcrumbs-react-router branch from 0aaff20 to efb296e Compare May 6, 2025 14:13
@VictoriaBeilsten-Edmands
Copy link
Collaborator Author

I've added SciReactUIProvider and updated the docs to replace ThemeProvider with this.

Copy link
Member

@akademy akademy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Just a few minor suggestions.

@akademy
Copy link
Member

akademy commented May 7, 2025

The SciReactUIProvider doesn't really fit in the "Themes" folder... but I don't really know the best place to put it...

@akademy
Copy link
Member

akademy commented May 7, 2025

Also, we need an export in index.ts:

export * from "./themes/SciReactUIProvider";

@VictoriaBeilsten-Edmands
Copy link
Collaborator Author

The SciReactUIProvider doesn't really fit in the "Themes" folder... but I don't really know the best place to put it...

I was a bit stuck on where to put it.

@akademy
Copy link
Member

akademy commented May 8, 2025

The SciReactUIProvider doesn't really fit in the "Themes" folder... but I don't really know the best place to put it...

I was a bit stuck on where to put it.

Maybe it's time to reorganise the component folder... controls, sections, general ?

@MattPrit
Copy link

MattPrit commented May 9, 2025

Are we sure we want to add a dependency to a specific routing library? Or has Diamond made a decision on which we should use?

@VictoriaBeilsten-Edmands
Copy link
Collaborator Author

Are we sure we want to add a dependency to a specific routing library? Or has Diamond made a decision on which we should use?

As far as I know there's no Diamond-wide decision on which we should use. I do think react-router is a good choice and what we should use here. I don't see a reason to diverge with multiple options.

@gfrn
Copy link
Collaborator

gfrn commented May 13, 2025

Are we sure we want to add a dependency to a specific routing library? Or has Diamond made a decision on which we should use?

As far as I know there's no Diamond-wide decision on which we should use. I do think react-router is a good choice and what we should use here. I don't see a reason to diverge with multiple options.

I think allowing people to do component "impersonation" in the breadcrumbs component is not going to lead to diversion, it would be useful for the following reasons:

  • If someone decides to use a non-BrowserRouter provider for react-router, then they are able to do so
  • We are not locked to one specific version of react-router, and being able to decouple updating react-router with updating sci-react-ui is really useful, because it might not be trivial for all people (especially if they are using/want to use version specific features, and going from v6 to v7 was not easy if you're using advanced features)
  • Not everyone is going to use react-router anyway, some people might elect to use simpler native browser navigation, or in my case, Next's own native navigation
  • If we choose to move to a different routing library in the future (like Tanstack Router), the switch is much easier, and we're not tying our UI to a routing library
  • This decreases the number of peer/direct dependencies, so when security updates come out, people won't have to wait on us updating sci-react-ui, so this is a safer option
  • It's not a "free" win, but it's at least technically feasible, and MUI already does this for plenty of components (in fact, this is a feature which is being used in this PR)

@VictoriaBeilsten-Edmands
Copy link
Collaborator Author

Are we sure we want to add a dependency to a specific routing library? Or has Diamond made a decision on which we should use?

As far as I know there's no Diamond-wide decision on which we should use. I do think react-router is a good choice and what we should use here. I don't see a reason to diverge with multiple options.

I think allowing people to do component "impersonation" in the breadcrumbs component is not going to lead to diversion, it would be useful for the following reasons:

* If someone decides to use a non-`BrowserRouter` provider for `react-router`, then they are able to do so

* We are not locked to one specific version of `react-router`, and being able to decouple updating `react-router` with updating `sci-react-ui` is really useful, because it might not be trivial for all people (especially if they are using/want to use version specific features, and going from v6 to v7 was not easy if you're using advanced features)

* Not everyone is going to use `react-router` anyway, some people might elect to use simpler native browser navigation, or in my case, Next's own native navigation

* If we choose to move to a different routing library in the future (like Tanstack Router), the switch is much easier, and we're not tying our UI to a routing library

* This decreases the number of peer/direct dependencies, so when security updates come out, people won't have to wait on us updating `sci-react-ui`, so this is a safer option

* It's not a "free" win, but it's at least technically feasible, and MUI already does this for plenty of components (in fact, this is a feature which is being used in this PR)

I could change the Breadcrumbs component and pass a LinkComponent e.g.

interface BreadcrumbsProps {
  path: string | string[] | CustomLink[];
  linkComponent: React.ElementType
  rootProps?: PaperProps;
  muiBreadcrumbsProps?: Mui_BreadcrumbsProps;
}

Then this can be used with whatever routing library e.g. Link from react-router-dom/ next etc.
We wouldn't have the SciReactUIProvider if we want to keep the dependency out of the library, so that would be removed.

@VictoriaBeilsten-Edmands
Copy link
Collaborator Author

The SciReactUIProvider doesn't really fit in the "Themes" folder... but I don't really know the best place to put it...

I was a bit stuck on where to put it.

Maybe it's time to reorganise the component folder... controls, sections, general ?

Shall we go with component/controls and component/navigation to mirror the storybook. I quite like those categories.

@gfrn
Copy link
Collaborator

gfrn commented May 14, 2025

Are we sure we want to add a dependency to a specific routing library? Or has Diamond made a decision on which we should use?

As far as I know there's no Diamond-wide decision on which we should use. I do think react-router is a good choice and what we should use here. I don't see a reason to diverge with multiple options.

I think allowing people to do component "impersonation" in the breadcrumbs component is not going to lead to diversion, it would be useful for the following reasons:

* If someone decides to use a non-`BrowserRouter` provider for `react-router`, then they are able to do so

* We are not locked to one specific version of `react-router`, and being able to decouple updating `react-router` with updating `sci-react-ui` is really useful, because it might not be trivial for all people (especially if they are using/want to use version specific features, and going from v6 to v7 was not easy if you're using advanced features)

* Not everyone is going to use `react-router` anyway, some people might elect to use simpler native browser navigation, or in my case, Next's own native navigation

* If we choose to move to a different routing library in the future (like Tanstack Router), the switch is much easier, and we're not tying our UI to a routing library

* This decreases the number of peer/direct dependencies, so when security updates come out, people won't have to wait on us updating `sci-react-ui`, so this is a safer option

* It's not a "free" win, but it's at least technically feasible, and MUI already does this for plenty of components (in fact, this is a feature which is being used in this PR)

I could change the Breadcrumbs component and pass a LinkComponent e.g.

interface BreadcrumbsProps {
  path: string | string[] | CustomLink[];
  linkComponent: React.ElementType
  rootProps?: PaperProps;
  muiBreadcrumbsProps?: Mui_BreadcrumbsProps;
}

Then this can be used with whatever routing library e.g. Link from react-router-dom/ next etc. We wouldn't have the SciReactUIProvider if we want to keep the dependency out of the library, so that would be removed.

I think this is a nice solution (to allow users to set both the link component and the prop each breadcrumb would use in that link component), and removing the provider surely would make things easier in the future!

@VictoriaBeilsten-Edmands VictoriaBeilsten-Edmands force-pushed the vbe/breadcrumbs-react-router branch 3 times, most recently from e9e653a to 6ad9e23 Compare May 15, 2025 14:54
@VictoriaBeilsten-Edmands VictoriaBeilsten-Edmands force-pushed the vbe/breadcrumbs-react-router branch from 6ad9e23 to 1a36fe7 Compare May 15, 2025 15:00
@VictoriaBeilsten-Edmands VictoriaBeilsten-Edmands merged commit ca9e2f8 into main May 20, 2025
1 check passed
@VictoriaBeilsten-Edmands VictoriaBeilsten-Edmands deleted the vbe/breadcrumbs-react-router branch May 20, 2025 15:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support routing library navigation in Breadcrumbs component
4 participants